//
//  NearbyController.m
//  7.13苏宁框架
//
//  Created by mini on 15/7/17.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "NearbyController.h"

#import "NearbyCell.h"
#import "NearbyHeadModel.h"
#import "Common.h"
#import "DSZMainViewController.h"
@interface NearbyController ()
@property(nonatomic,strong)LocationView *location;
@end

@implementation NearbyController

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.bounces = NO;
    NearbyHeadView *headView = [[NearbyHeadView alloc]init];
    headView.delegate =self;
    self.tableView.tableHeaderView = headView;
    //创建位置视图，让他摆在屏幕下方
    _location = [LocationView createLocationView];
    _location.top = 480;
    _location.delegate = self;
    self.location = _location;
    [self.view addSubview:_location];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    int count = 0 ;
    if (section==0) {
        count = 2;
    }
    else if (section == 1) {
        count = 2;
    }
    return count;
}

-(NSArray*)total
{
    _total = [NSArray array];
    _total = [NearbyHeadModel modelArrayWithFilename:@"nearbyHead.plist"];
    return _total;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NearbyCell *cell = [NearbyCell createCell:tableView];
    if (indexPath.section == 0 && indexPath.row == 0) {
        cell.model = self.total[0];
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        cell.model = self.total[1];
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        cell.model = self.total[2];
    }
    if (indexPath.section == 1 && indexPath.row == 1) {
        cell.model = self.total[3];
    }
        return cell;
}


//设置标头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    int height = 0;
    if (section == 0) {
        height = 20;
    }
    if (section==1) {
        height = 0;
    }
    return height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    int height = 0;
    if (section == 0) {
        height = 10;
    }
    if (section==1) {
        height = -10;
    }
    return height;
}

//代理
-(void)returnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
//显示选择区域
-(void)locationClick
{
   //位置视图出来
    _location.bottom = 480;
    //分栏隐藏
    DSZMainViewController *main = (DSZMainViewController*)self.tabBarController;
    [main hiddenMainTabbar:YES];
}
//关闭显示区域
-(void)closeLocationView
{
    //显示分栏和关闭显示区域
    //位置视图出来
    _location.top = 480;
    //分栏隐藏
    DSZMainViewController *main = (DSZMainViewController*)self.tabBarController;
    [main hiddenMainTabbar:NO];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
